/* 
  SOAP-Request-Error-Handler: 
  - handles cases when SOAP-requests fail
*/

function SoapRequestErrorHandler(){
    this.errors = [];
    this.warning = [];
}

/**
 * Puts an error message to an Array
 * @param {String} errMsg
 * @param {boolean} showMessage if true: error message is displayed in ul#error. (error Array is emptied)
 */
SoapRequestErrorHandler.prototype.error = function(errMsg, showMessage){
    showMessage = typeof showMessage == 'undefined' ? true : showMessage;
    this.errors.push(errMsg);
    if(showMessage){
        this.showErrorMessages();
    }
}

/**
 * Puts an warn message to an Array
 * @param {String} warnMsg
 * @param {boolean} showMessage if true: warn message is displayed in ul#warn. (warning Array is emptied)
 */
SoapRequestErrorHandler.prototype.warn = function(warnMsg, showMessage){
    showMessage = typeof showMessage == 'undefined' ? true : showMessage;
    this.warning.push(warnMsg);
    if(showMessage){
        this.showWarnMessages();
    }
}

/**
 * warn messages are displayed in ul#warn. (warning Array is emptied)
 */
SoapRequestErrorHandler.prototype.showWarnMessages = function(){
    for(var key in this.warning){
        $('#warn').append('<li>' + this.warning[key] + '</li>');
    }
    this.warning = [];
}

/**
 * erro messages are displayed in ul#error. (error Array is emptied)
 */
SoapRequestErrorHandler.prototype.showErrorMessages = function(){
    for(var key in this.errors){
        $('#error').append('<li>' + this.errors[key] + '</li>');
    }
    this.errors = [];
}

/**
 * Empties ul#error and ul#warn elements
 */
SoapRequestErrorHandler.prototype.removeAllMessages = function(){
    $('#error').html('');
    $('#warn').html('');
}

/**
 * Empties ul#warn element
 */
SoapRequestErrorHandler.prototype.removeWarnings = function(){
    $('#warn').html('');
}

/**
 * Empties ul#error element
 */
SoapRequestErrorHandler.prototype.removeErrors = function(){
    $('#error').html('');
}
